package com.ytjj.bigdata.service;

import com.github.pagehelper.PageHelper;
import com.ytjj.bigdata.dao.AdsOrderCountMapper;
import com.ytjj.bigdata.entity.AdsOrderCount;
import com.ytjj.bigdata.model.dto.AdsOrderCountDto;
import com.ytjj.bigdata.model.response.AdsOrderResponse;
import com.ytjj.common.api.CommonPageExtend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class AdsOrderCountService {
    @Resource
    private AdsOrderCountMapper adsOrderCountMapper;

    public CommonPageExtend selectAdsOrder(AdsOrderCountDto adsOrderCountDto) {
//        AdsOrderResponse response = new AdsOrderResponse();
        PageHelper.startPage(adsOrderCountDto.getPageNum(),adsOrderCountDto.getPageSize());
        List<AdsOrderCount> list = adsOrderCountMapper.selectAdsOrder(adsOrderCountDto);

        if (CollectionUtils.isEmpty(list)) {
            return new CommonPageExtend();
        }

        List<AdsOrderResponse> orderCount = adsOrderCountMapper.findOrderCount(adsOrderCountDto);
        CommonPageExtend<AdsOrderCount> pageInfo = CommonPageExtend.restPage(list);
        AdsOrderResponse response = orderCount.get(0);

        pageInfo.setFlagCount(response.getFlagCount());
        pageInfo.setOrderCountCount(response.getOrderCountCount());
        pageInfo.setPayCountCount(response.getPayCountCount());

        return pageInfo;

//        AdsOrderVo orderVo = new AdsOrderVo();
//        orderVo.setAdsOrderCountList(list);
//        orderVo.setOrderResponses(orderCount);

//        response.setFlagCount(list.stream().filter(item -> null != item.getFlag()).mapToInt(AdsOrderCount::getFlag).sum());
//        response.setOrderCountCount(list.stream().filter(item -> null != item.getOrderCount()).mapToInt(AdsOrderCount::getOrderCount).sum());
//        response.setPayCountCount(list.stream().filter(item -> null != item.getPayCount()).mapToInt(AdsOrderCount::getPayCount).sum());
//
//        CommonPageExtend pageInfo = CommonPageExtend.restPage(list);
//        pageInfo.setFlagCount(response.getFlagCount());
//        pageInfo.setOrderCountCount(response.getOrderCountCount());
//        pageInfo.setPayCountCount(response.getPayCountCount());

//        return orderVo;
    }
}
